﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace Prototype1.AdminPage
{
    public partial class WF_ManageUsers : System.Web.UI.Page
    {
        

        protected void Page_Load(object sender, EventArgs e)
        {
            IEnumerator<User> x = null;
            using (DataAccessDataContext dc = new DataAccessDataContext())
            {
                var query = from pfile in dc.Users
                            select pfile;

                
                x = query.GetEnumerator();

                if (x.MoveNext() && x.Current != null)
                    UpdateUserList(x);
            }
            
            
            
        }


        protected void UpdateUserList(IEnumerator<User> x)
        {
            this.UserList.Controls.Add(new LiteralControl("<table>"));
            this.UserList.Controls.Add(new LiteralControl("<tr>"));
            this.UserList.Controls.Add(new LiteralControl("<th>Short name</th>"));
            this.UserList.Controls.Add(new LiteralControl("<th>Email</th>"));
            this.UserList.Controls.Add(new LiteralControl("<th>Password</th>"));
            this.UserList.Controls.Add(new LiteralControl("<th></th>"));
            this.UserList.Controls.Add(new LiteralControl("</tr>"));


            do
            {
                InsertLine(x.Current);
            }
            while (x.MoveNext());
                            

            this.UserList.Controls.Add(new LiteralControl("</table>"));
        }

        private static string tag = "SPECIALTAG";

        protected void InsertLine(User u)
        {
            Button b = new Button();
            b.ID = tag + u.email;
            b.Text = "Delete";


            this.UserList.Controls.Add(new LiteralControl("<tr><td>" + u.Shortname + "</td><td>" + u.email + "</td><td>" + u.Password + "</td><td>"));
            this.UserList.Controls.Add(b);
            this.UserList.Controls.Add(new LiteralControl("</td></tr>"));
        }
    }
}
